﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using DigiLib;

public partial class controls_admin_AdvertisingAdd : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
            loadGallery();
        }
    }
    protected void loadGallery()
    {
        DataTable objDT = BO_portal_galleries.SelectAll(1);
        lbxCategories.DataTextField = "GALLERY_NAME";
        lbxCategories.DataValueField = "GALLERY_ID";
        lbxCategories.DataSource = objDT;
        lbxCategories.DataBind();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string fileName = base.Upload("gallery", String.Empty, fulAdv, divMessage, false);
        if (string.IsNullOrEmpty(fileName))
        {
            fileName = txtDirectLink.Text;
        }
        try
        {
            string title = txtTitle.Text.Trim();
            bool display = chbDisplay.Checked;
            DateTime endDate = DateTime.Now;
            DateTime startDate = DateTime.Now;
            string result = BO_portal_galleries_details.Insert(Convert.ToInt32(lbxCategories.SelectedValue), title
                    , fileName, 0, display, 0, DateTime.Now, Administrator.USER_NAME, DateTime.Now, Administrator.USER_NAME, true);
            if (result.Equals("0"))
                divMessage.InnerHtml = MessageBox.Error("Thông Báo", "Lỗi trong quá trình truyền tải dữ liệu. Mong bạn trở lại sau .");
            else
            {
                divMessage.InnerHtml = MessageBox.Success("Thông Báo", "Thực hiện thành công .");
                Clear(this.Controls);
            }
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi xảy ra !<br />" + ex.Message);
        }
    }
}
